//package fileupdown;
//
//import javax.servlet.ServletException;
//import javax.servlet.ServletOutputStream;
//import javax.servlet.annotation.MultipartConfig;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.*;
//import java.net.URLEncoder;
//
//@WebServlet("/download")
//@MultipartConfig
//public class FileDownload extends HttpServlet {
//    @Override
//    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
////        super.service(req, resp);
//        //获取上传到服务器的文件名
//        String submittedFileName = req.getParameter("name");
//        File file = new File("D:\\CodeAll\\code\\FirstWeb\\src\\main\\webapp\\resourse\\" + submittedFileName);
//        if (file.exists()){
//            FileInputStream fileInputStream = new FileInputStream(file);
//            resp.setContentType("application/octet-stream");
//            // 对文件名进行URL编码
//            String encodedFileName = URLEncoder.encode(submittedFileName, "UTF-8");
//            resp.setHeader("Content-Disposition", "attachment; filename="+encodedFileName);
//            ServletOutputStream outputStream = resp.getOutputStream();
//            byte[] bytes = new byte[1024];
//            int len = 0;
//            while (-1!=(len=fileInputStream.read(bytes))){
//                outputStream.write(bytes,0,len);
//            }
//            outputStream.flush();
//            fileInputStream.close();
//        }else {
//            //进行文件不存在的处理
//        }
//    }
//}
